﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Web.Class;
using Entity;
using BLL.Access;
using BLL;
using System.Data;

namespace Web.Controls.LAIHAN
{
    public partial class UCLHFenHuShenPiXX : System.Web.UI.UserControl,IUCLHOperate
    {
        #region 属性
        private eLaiHanLCBH laiHanLCBH;

        public eLaiHanLCBH LaiHanLCBH
        {
            get { return laiHanLCBH; }
            set { laiHanLCBH = value; }
        }

        #endregion

        #region 变量
        YS_LH_FENHUXXBLL BllFenHuXX = new YS_LH_FENHUXXBLL();

        #endregion

        #region 事件

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InitControl();
            }
        }

        #endregion

        #region 方法
        public void InitControl()
        {
            if (LaiHanLCBH == eLaiHanLCBH.业务员)
            {
                YiJianTable.Visible = false;
                tdShuRuRXX.InnerHtml = "业务员意见：";
            }
            else if (LaiHanLCBH == eLaiHanLCBH.主任)
            {
                tdShuRuRXX.InnerHtml = "主任意见：";
                tdZhuRen.Visible = false;
                tdZhuRenXX.Visible = false;
                tdJieShuiK.Visible = false;
                tdJieShuiKXX.Visible = false;
                tdJiCaiK.Visible = false;
                tdJiCaiKXX.Visible = false;
            }
            else if (LaiHanLCBH == eLaiHanLCBH.节水科)
            {
                tdShuRuRXX.InnerHtml = "节水科意见：";
                tdJieShuiK.Visible = false;
                tdJieShuiKXX.Visible = false;
                tdJiCaiK.Visible = false;
                tdJiCaiKXX.Visible = false;
            }
            else if (LaiHanLCBH == eLaiHanLCBH.计财科)
            {
                tdShuRuRXX.InnerHtml = "计财科意见：";
               
                tdJiCaiK.Visible = false;
                tdJiCaiKXX.Visible = false;
            }
        }
        public void SetEnabled(bool b)
        {
            txtJianYiXX.Enabled = b;
            CShenPiBTY.Enabled = b;
            CShenPiTY.Enabled = b;
        }
        public ValidateRS Validate()
        {
            ValidateRS rs = new ValidateRS();
            rs.IsSuccess = false;
            if (!CShenPiBTY.Checked && !CShenPiTY.Checked)
            {
                rs.Msg = "请选择审批结果";
                CShenPiTY.Focus();
            }
            if (txtJianYiXX.Text.Trim().Length == 0)
            {
                rs.Msg = "意见信息不能为空";
                txtJianYiXX.Focus();
            }
            rs.IsSuccess = true;
            return rs;

        }

        public void ClearInfo()
        {
            txtJianYiXX.Text = "";
            txtJiCai.Text = "";
            txtJieShui.Text = "";
            txtZhuRen.Text = "";
            CShenPiBTY.Checked = false;
            CShenPiTY.Checked = false;
        }
        public void UpdateLaiHanXX(YS_LH_LAIHANXX laihanxx,bool b)
        {
            if (b)
            {

            }
            else {
                string where = "s_yonghuhfather='{0}' and s_laihanbh='{1}' and i_jlzt=0 ";
                string updatecol = "";
                if (this.LaiHanLCBH == eLaiHanLCBH.业务员)
                {
                    updatecol = "S_YEWUY='{0}',s_shenpiyj='{1}'";                    
                }
                else if (this.LaiHanLCBH == eLaiHanLCBH.主任)
                {
                    updatecol = "S_ZHUREN='{0}',s_shenpiyj='{1}'";
                }
                else if (this.LaiHanLCBH == eLaiHanLCBH.节水科)
                {
                    updatecol = "S_JIESHUI='{0}',s_shenpiyj='{1}'";
                }
                else if (this.LaiHanLCBH == eLaiHanLCBH.计财科)
                {
                    updatecol = "S_JICAI='{0}',s_shenpiyj='{1}'";
                }
                if (updatecol.Trim().Length > 0)
                {
                    where = string.Format(where,laihanxx.S_YONGHUBH,laihanxx.S_LAIHANBH);
                    updatecol = string.Format(updatecol,txtJianYiXX.Text,(int)this.laiHanLCBH);
                    BllFenHuXX.UpdateYS_LH_FENHUXXesDynamic(updatecol,where);
                }
            }
        }
        public void LoadInfo(YS_LH_LAIHANXX laihanxx)
        {
            string where = " S_LAIHANBH='{0}' and S_YONGHUHFATHER='{1}' and i_Y={2} and i_jlzt=0 ";
            where = string.Format(where,laihanxx.S_LAIHANBH,laihanxx.S_YONGHUBH,laihanxx.I_Y);
            DataTable dt = BllFenHuXX.SelectYS_LH_FENHUXXesDynamic(where,"",null);
            if (dt != null && dt.Rows.Count > 0)
            {
                if (LaiHanLCBH == eLaiHanLCBH.业务员)
                {
                    txtJianYiXX.Text = dt.Rows[0]["S_YeWuY"].ToString();
                    
                }
                else if (LaiHanLCBH == eLaiHanLCBH.主任)
                {
                    txtJianYiXX.Text = dt.Rows[0]["S_ZHUREN"].ToString();
                    txtZhuRen.Text = dt.Rows[0]["S_ZHUREN"].ToString();
                }
                else if (LaiHanLCBH == eLaiHanLCBH.节水科)
                {
                    txtJianYiXX.Text = dt.Rows[0]["S_JIESHUI"].ToString();
                    txtJieShui.Text = dt.Rows[0]["S_JIESHUI"].ToString();
                }
                else if (LaiHanLCBH == eLaiHanLCBH.计财科)
                {
                    txtJianYiXX.Text = dt.Rows[0]["S_JICAI"].ToString();
                    txtJiCai.Text = dt.Rows[0]["S_JICAI"].ToString();
                }
            }
        }

        #endregion
    }
}